﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using KCMS.BusinessLogic.Models;

namespace KCMS.Areas.Admin.Controllers
{
    public class NewsController : Controller
    {
        private INewsService newsService = ObjectFactory.GetInstance<INewsService>();
        public ActionResult Index()
        {
            var newss = newsService.getAll();
            return View(newss);
        }
        [HttpGet]
        public ActionResult Create()
        {
            var news = new News();
            return View(news);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(News model)
        {
            newsService.save(model);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Edit(Guid id)
        {
            var model = newsService.getById(id);
            return View(model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(News model)
        {
            //News old = productService.getById(news.Id);

            //UpdateModel<News>(news);
            newsService.update(model);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Delete(Guid id)
        {
            var model = newsService.getById(id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Delete(News model)
        {
            newsService.delete(model.Id);
            return RedirectToAction("Index");
        }

    }
}
